//    Copyright (C) 2013  <lugocreation@gmail.com>
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>
package org.jpgolay.wi.agency;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Collection;
import org.jpgolay.wi.persistence.ObjectCRUD;
import org.jpgolay.wi.persistence.SQLList;

// Referenced classes of package org.jpgolay.wi.agency:
//            Agency
public class AgencyCRUD
        implements Serializable {

    public AgencyCRUD() {
        crud = new ObjectCRUD();
    }

    public boolean find(Integer id) {
        data = readAgency(id);
        return data != null;
    }

    public Collection findAll() {
        return readAllAgency();
    }

    public boolean isPassword(String pass) {
        return verifyIfExist("SELECT ID FROM AGENCY WHERE PASS='" + pass + "'");
    }

    public boolean modify() {
        return updateAgency();
    }

    public boolean create() {
        Integer id = createAgency();
        if (id != null) {
            data = readAgency(id);
            return true;
        } else {
            return false;
        }
    }

    public boolean remove() {
        return deleteAgency();
    }

    public String getId() {
        return data.getId().toString();
    }

    public String getPass() {
        return data.getPass();
    }

    public void setPass(String pass) {
        data.setPass(pass);
    }

    public String getCompagny() {
        return data.getCompagny();
    }

    public void setCompagny(String compagny) {
        data.setCompagny(compagny);
    }

    public String getStatus() {
        return data.getStatus();
    }

    public void setStatus(String status) {
        data.setStatus(status);
    }

    public String getAddrLn1() {
        return data.getAddrLn1();
    }

    public void setAddrLn1(String addrLn1) {
        data.setAddrLn1(addrLn1);
    }

    public String getAddrLn2() {
        return data.getAddrLn2();
    }

    public void setAddrLn2(String addrLn2) {
        data.setAddrLn2(addrLn2);
    }

    public String getCity() {
        return data.getCity();
    }

    public void setCity(String city) {
        data.setCity(city);
    }

    public String getCounty() {
        return data.getCounty();
    }

    public void setCounty(String county) {
        data.setCounty(county);
    }

    public String getZip() {
        return data.getZip();
    }

    public void setZip(String zip) {
        data.setZip(zip);
    }

    public String getTel1() {
        return data.getTel1();
    }

    public void setTel1(String tel1) {
        data.setTel1(tel1);
    }

    public String getTel2() {
        return data.getTel2();
    }

    public void setTel2(String tel2) {
        data.setTel2(tel2);
    }

    public String getFax() {
        return data.getFax();
    }

    public void setFax(String fax) {
        data.setFax(fax);
    }

    public String getEmail() {
        return data.getEmail();
    }

    public void setEmail(String email) {
        data.setEmail(email);
    }

    public String getWeb() {
        return data.getWeb();
    }

    public void setWeb(String web) {
        data.setWeb(web);
    }

    public Integer getAccess() {
        return data.getAccess();
    }

    public void setAccess(Integer access) {
        data.setAccess(access);
    }

    public String getWww() {
        return data.getWww();
    }

    public void setWww(String www) {
        data.setWww(www);
    }

    public String getWelcomeEmail() {
        return data.getWelcomeEmail();
    }

    public void setWelcomeEmail(String welcomeEmail) {
        data.setWelcomeEmail(welcomeEmail);
    }

    public String getWelcomeTitle() {
        return data.getWelcomeTitle();
    }

    public void setWelcomeTitle(String welcomeTitle) {
        data.setWelcomeTitle(welcomeTitle);
    }

    public String getNewAdEmailUp() {
        return data.getNewAdEmailUp();
    }

    public void setNewAdEmailUp(String newAdEmailUp) {
        data.setNewAdEmailUp(newAdEmailUp);
    }

    public String getNewAdEmailDown() {
        return data.getNewAdEmailDown();
    }

    public void setNewAdEmailDown(String newAdEmailDown) {
        data.setNewAdEmailDown(newAdEmailDown);
    }

    public Integer getGroupId() {
        return data.getGroupId();
    }

    public void setGroupId(Integer groupId) {
        data.setGroupId(groupId);
    }

    public String getUsername() {
        return data.getUsername();
    }

    public void setUsername(String username) {
        data.setUsername(username);
    }

    public String getSmtp() {
        return data.getSmtp();
    }

    public void setSmtp(String smtp) {
        data.setSmtp(smtp);
    }

    public String getNewAdTitle() {
        return data.getNewAdTitle();
    }

    public void setNewAdTitle(String newAdTitle) {
        data.setNewAdTitle(newAdTitle);
    }

    public String getExpiryDate() {
        return data.getExpiryDate();
    }

    public void setExpiryDate(String expiryDate) {
        data.setExpiryDate(expiryDate);
    }

    public BigDecimal getPaymentDue() {
        return data.getPaymentDue();
    }

    public void setPaymentDue(BigDecimal paymentDue) {
        data.setPaymentDue(paymentDue);
    }

    public String getComment() {
        return data.getComment();
    }

    public void setComment(String comment) {
        data.setComment(comment);
    }

    public byte[] getLogo() {
        return data.getLogo();
    }

    public void setLogo(byte logo[]) {
        data.setLogo(logo);
    }

    public Agency getData() {
        return data;
    }

    public void setData(Agency agency) {
        data = agency;
    }

    private Integer createAgency() {
        return crud.create(5);
    }

    private Agency readAgency(Integer id) {
        return (Agency) crud.read(id, 5);
    }

    private Collection readAllAgency() {
        return crud.readAll(null, 5);
    }

    private boolean updateAgency() {
        return crud.update(data, 5);
    }

    private boolean deleteAgency() {
        return crud.delete(data.getId(), data.getLastUpdate(), 5);
    }

    private boolean verifyIfExist(String sql) {
        SQLList sqlList = new SQLList();
        return sqlList.search(sql);
    }
    private Agency data;
    private ObjectCRUD crud;
}
